package com.ycomputer.adapter;

import java.util.List;
import java.util.Map;

import com.ycomputer.pizzashow.R;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class TextMenuAdapter extends BaseAdapter{

	private List<? extends Map<String, ?>> mData;
	private int mItemResource;
	private LayoutInflater mInflater;

	public TextMenuAdapter(Context context, List<? extends Map<String, ?>> data, int resource) {
		super();
		this.mData = data;
		this.mItemResource = resource;
		mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
	}

	@Override
	public int getCount() {
		return mData.size();
	}

	@Override
	public Object getItem(int position) {
		return mData.get(position);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		return createViewFromResource(position, convertView, parent, mItemResource);
	}

	private View createViewFromResource(int position, View convertView, ViewGroup parent, int resource) {
		View v;
		if (convertView == null) {
			v = mInflater.inflate(resource, parent, false);
		} else {
			v = convertView;
		}

		bindView(position, v);

		return v;
	}

	private void bindView(int position, View view) {
		Map dataSet = mData.get(position);
        if (dataSet == null) {
            return;
        }
        //pizza name
        ((TextView)view.findViewById(R.id.text_menu_pizza_name)).setText(dataSet.get("name").toString());
        //pizza desc
        ((TextView)view.findViewById(R.id.text_menu_pizza_price)).setText(dataSet.get("price").toString());
        //pizza desc
        ((TextView)view.findViewById(R.id.text_menu_pizza_desc)).setText(dataSet.get("desc").toString());
	}
	
}
